﻿/*=================================================================
* 版权信息：Copyright (C) 2005-2011 捷点科技 All Rights Reserved.
* 文件名称：Login.aspx.cs
* 创建标识：曾乃强 15158756652 2011-03-14 03:03:16
* 修改标识：
* 功能描述：
===================================================================*/
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CNVP.Framework;
using CNVP.Framework.Utils;
using CNVP.Config;

namespace CNVP.JShop.Web.Admin
{
    public partial class Login : System.Web.UI.Page
    {
        BLL.CNVP_Admin bll = new BLL.CNVP_Admin();
        protected void Page_Load(object sender, EventArgs e)
        {
            var action = Request.QueryString["action"];

                if (action!=null && action == "login")
                {
                    if (string.IsNullOrEmpty(Request.Form["txtUserName"]))
                    {
                        BasePage.MessageBoxGoHistory("请输入用户名！");
                    }
                    else if (string.IsNullOrEmpty(Request.Form["txtUserPwd"]))
                    {
                        BasePage.MessageBoxGoHistory("请输入密码！");
                    }
                    else if (string.IsNullOrEmpty(Request.Form["txtVerifyCode"]))
                    {
                        BasePage.MessageBoxGoHistory("请输入验证码！");
                    }
                    else
                    {
                        if (Session["CheckCode"] != null)
                        {
                            if (Session["CheckCode"].ToString() == Request.Form["txtVerifyCode"].Trim().ToLower())
                            {
                                Model.CNVP_Admin model = new Model.CNVP_Admin();
                                model.AdminName = Request.Form["txtUserName"].Trim();
                                model.AdminPass = EncryptUtils.MD5(Request.Form["txtUserPwd"].Trim());
                                model.IsLock = 0;
                                model =bll.cust_LoginByName(model);
                                if (model !=null)
                                {
                                    Response.Cookies["" + UIConfig.CookiesName + "AdminID"].Value = EncryptUtils.EncodeCookies(model.ID.ToString());
                                    Response.Cookies["" + UIConfig.CookiesName + "AdminID"].Expires = DateTime.Now.AddDays(12);
                                    Response.Cookies["" + UIConfig.CookiesName + ""].Value = EncryptUtils.EncodeCookies(model.AdminName);
                                    Response.Cookies["" + UIConfig.CookiesName + ""].Expires = DateTime.Now.AddDays(12);
                                    Response.Cookies["" + UIConfig.CookiesName + "RoleID"].Value = EncryptUtils.EncodeCookies(model.RoleID.ToString());
                                    Response.Cookies["" + UIConfig.CookiesName + "RoleID"].Expires = DateTime.Now.AddDays(12);
                                    //更新
                                    model.LastLoginIp = HttpContext.Current.Request.UserHostAddress;
                                    model.LastLoginTime = DateTime.Now.AddMinutes(1);
                                    bll.cust_UpdateLogin(model);
                                    Response.Redirect("Index.aspx", false);
                                }
                                else
                                {
                                    BasePage.MessageBoxGoHistory("登录失败！");
                                }
                            }
                            else
                            {
                                BasePage.MessageBoxGoHistory("输入验证码有误！");
                            }
                        }
                        else
                        {
                            Response.Redirect("Login.aspx");
                        }
                    }
            }
        }
    }
}
